You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: authenticate loopback debug adapter sessions and bind no-config JDWP to loopback - #1736
↑ Negotiates startDebugSessionprotocolVersion: 2 strictly over literal loopback endpoints (127.0.0.1 / ::1) with JavaDebug-Auth handshake framing, O(n) chunk-queued UTF-8 Content-Length parsing, and a 127.0.0.1 numeric-port fallback for older JDTLS debug server bundles. ↑ Binds all no-config JDWP wrapper scripts strictly to address=127.0.0.1:0 and preserves LF line endings for POSIX shells via .gitattributes. ↓ Full protocolVersion: 2 session authentication pairs with companion server PR microsoft/java-debug#653 when bundling the next server plugin JAR.
Diagnosis confidence
10/10
↑ Directly traced unauthenticated DebugAdapterServer(debugServerPort) client connection setup and wildcard address=0 JDWP agent options across bundled/scripts/noConfigScripts/* and src/noConfigDebugInit.ts.
Evidence fit
10/10
↑ Verified with TSLint, webpack production packaging (vsce package), Mocha extension-host tests (including live jdwp-wrapper.js JVM execution), and live end-to-end .vsix verification in VS Code 1.147.0.
Summary
Companion client changes for microsoft/java-debug#653. Authenticates loopback Debug Adapter Protocol (DAP) sessions via protocolVersion: 2 negotiation and restricts no-config JDWP listeners to 127.0.0.1.
Passes {"protocolVersion": 2} to vscode.java.startDebugSession, validates literal loopback hosts (127.0.0.1 / ::1), sends the per-session JavaDebug-Auth handshake header prior to queued DAP frames, parses multi-byte UTF-8 Content-Length frames incrementally with bounded header/payload limits, fails post-close requests deterministically, and retains a 127.0.0.1DebugAdapterServer fallback when paired with older server bundles that return a numeric port.
Binds -agentlib:jdwp strictly to address=127.0.0.1:0, preserves host: "127.0.0.1" when forwarding attach endpoints, and enforces LF line endings for POSIX wrapper scripts via .gitattributes.
Built and verified .vsix paired with microsoft/java-debug#653 end-to-end in VS Code 1.147.0 with redhat.java across launch, noDebug: true, and jdwp-wrapper.js loopback attach.
…JDWP to loopback
- Negotiate startDebugSession protocol v2 ({ protocolVersion: 2 }) and
connect via an inline AuthenticatedSocketDebugAdapter over 127.0.0.1 that
sends the per-session JavaDebug-Auth handshake before queued DAP requests,
with incremental UTF-8 byte framing and legacy numeric-port loopback fallback.
- Bind no-config debug wrapper scripts (debugjava, debugjava.fish,
debugjava.ps1, debugjava.bat, and jdwp-wrapper.js) strictly to
�ddress=127.0.0.1:0 and preserve 127.0.0.1 in
oConfigDebugInit.ts.
- Add Mocha coverage for AuthenticatedSocketDebugAdapter, descriptor
negotiation, and loopback JDWP wrapper execution.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This PR adds client support for authenticated Java debug adapter sessions and restricts no-config JDWP listeners to IPv4 loopback. Full authentication depends on the companion server changes in microsoft/java-debug#653.
Changes:
Negotiates protocol v2 and adds authenticated socket transport, retaining a loopback-only legacy fallback.
Binds no-config JDWP listeners to 127.0.0.1 and preserves that address when attaching.
Adds transport and wrapper tests and enforces LF endings for the Fish script.
File
Description
test/noConfigDebugInit.test.ts
Checks loopback bindings and Fish line endings.
test/authenticatedDebugAdapter.test.ts
Tests authentication, framing, fallback, and JVM endpoint capture.
src/noConfigDebugInit.ts
Preserves IPv4 loopback in attach configurations.
src/languageServerPlugin.ts
Requests protocol v2 session descriptors.
src/javaDebugAdapterDescriptorFactory.ts
Selects authenticated transport or legacy loopback fallback.
src/authenticatedDebugAdapter.ts
Implements authenticated socket transport and DAP framing.
- Immediately synthesize a failure DAP response when handleMessage receives a
request after the socket has closed instead of queuing dead outbound frames.
- Enforce MAX_HEADER_BYTES even when the \r\n\r\n header terminator arrives in
the same TCP chunk as the oversized header.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The authenticated connection accepts non-loopback destinations, exposing the token and DAP traffic, while quadratic response buffering can stall the extension host.
Avoid quadratic copying while buffering response bodies
src/authenticatedDebugAdapter.ts:153
This concatenates the entire partially received body on every socket chunk, making buffering quadratic in the response size. A valid 32 MiB response arriving in 64 KiB chunks copies about 8 GiB before parsing; large string evaluations or variable responses can therefore stall the extension host and create substantial allocation pressure. Please retain chunks with a read offset and concatenate only once per complete frame, or fill a bounded body buffer after reading Content-Length.
- Validate literal loopback host (127.0.0.1 or ::1) in both
JavaDebugAdapterDescriptorFactory and AuthenticatedSocketDebugAdapter before
opening any socket.
- Buffer inbound socket chunks in a chunk queue and assemble bytes once per
completed frame to avoid quadratic copying on large responses.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The tests do not actually split a UTF-8 character or cover IPv4 host forwarding, leaving both intended behaviors vulnerable to undetected regressions.
No open issues 🎉
2 previously missed issues
In code that hasn't changed since last review
Test forwarding an IPv4 client host
src/noConfigDebugInit.ts:159
The endpoint-handler tests only use host: "localhost", so they would not catch a regression that drops the new IPv4 host forwarding and breaks attach when localhost resolves to IPv6. Add a regression test in test/noConfigDebugStorage.test.ts with client.host: "127.0.0.1" that asserts startDebugging receives hostName: "127.0.0.1", while retaining the legacy-host case.
Split the test chunk inside the emoji
test/authenticatedDebugAdapter.test.ts:62
The length - 7 offset falls immediately before the four-byte rocket character, so both chunks are independently valid UTF-8. This test therefore does not exercise the split-character case it claims to cover and would miss a regression that decodes each incoming chunk separately. Split inside the emoji instead.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The security-sensitive DAP transport rewrite depends on unmerged microsoft/java-debug#653 and requires human validation of the packaged client/server pairing, legacy fallback, and cross-platform interoperability.
The client-side auth handshake and loopback framing changes look clean! To ensure we can monitor connection reliability after rollout and tune the new 5s handshake timeout on the server (microsoft/java-debug#653), could we add minimal telemetry in AuthenticatedSocketDebugAdapter (and JavaDebugAdapterDescriptorFactory)?
Specifically, existing session telemetry relies on fetchUsageData() after a session runs in ProtocolServer, which misses failures/timeouts that happen during socket connect or the JavaDebug-Auth handshake:
DAP handshake/connect success & failure rate: In AuthenticatedSocketDebugAdapter, emit a single event per session (no token/path/payload):
On receiving the first valid DAP response: success + durationMs (gives us P95/P99 latency and the success denominator).
If the socket closes or errors before the first response: failure + durationMs + enum reason (e.g. closed_before_first_response, socket_error, frame_error) + err.code (e.g. ECONNREFUSED, ECONNRESET, ETIMEDOUT), so we can spot ~5s auth handshake timeouts or ~30s accept timeouts.
Protocol fallback tracking: In JavaDebugAdapterDescriptorFactory, record whether v2 (authenticated) or v1_legacy_fallback was used so we can detect unexpected fallback spikes.
Emit a single `dapAuthHandshake` telemetry event per session from
`AuthenticatedSocketDebugAdapter` with outcome, sanitized failure reason/error code,
and monotonic `durationMs`, and emit `dapSessionProtocol` (`v2` vs
`v1_legacy_fallback`) from `JavaDebugAdapterDescriptorFactory`.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed to evaluate the risk of extension-host stalls from quadratic chunk draining, even for fragmented responses below the payload limit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
0a0e60aa6f25231ea836443255001956edde2e59startDebugSessionprotocolVersion: 2strictly over literal loopback endpoints (127.0.0.1/::1) withJavaDebug-Authhandshake framing,O(n)chunk-queued UTF-8Content-Lengthparsing, and a127.0.0.1numeric-port fallback for older JDTLS debug server bundles.↑ Binds all no-config JDWP wrapper scripts strictly to
address=127.0.0.1:0and preservesLFline endings for POSIX shells via.gitattributes.↓ Full
protocolVersion: 2session authentication pairs with companion server PRmicrosoft/java-debug#653when bundling the next server plugin JAR.DebugAdapterServer(debugServerPort)client connection setup and wildcardaddress=0JDWP agent options acrossbundled/scripts/noConfigScripts/*andsrc/noConfigDebugInit.ts.vsce package), Mocha extension-host tests (including livejdwp-wrapper.jsJVM execution), and live end-to-end.vsixverification in VS Code1.147.0.Summary
Companion client changes for microsoft/java-debug#653. Authenticates loopback Debug Adapter Protocol (DAP) sessions via
protocolVersion: 2negotiation and restricts no-config JDWP listeners to127.0.0.1.Changes
Authenticated loopback DAP client (
protocolVersion: 2)src/authenticatedDebugAdapter.ts,src/javaDebugAdapterDescriptorFactory.ts,src/languageServerPlugin.ts{"protocolVersion": 2}tovscode.java.startDebugSession, validates literal loopback hosts (127.0.0.1/::1), sends the per-sessionJavaDebug-Authhandshake header prior to queued DAP frames, parses multi-byte UTF-8Content-Lengthframes incrementally with bounded header/payload limits, fails post-close requests deterministically, and retains a127.0.0.1DebugAdapterServerfallback when paired with older server bundles that return a numeric port.Loopback-only no-config JDWP listeners
bundled/scripts/noConfigScripts/jdwp-wrapper.js,debugjava,debugjava.fish,debugjava.ps1,debugjava.bat,.gitattributes,src/noConfigDebugInit.ts-agentlib:jdwpstrictly toaddress=127.0.0.1:0, preserveshost: "127.0.0.1"when forwarding attach endpoints, and enforcesLFline endings for POSIX wrapper scripts via.gitattributes.Verification
npm run tslint,vsce package, andnpm testpassed (includingtest/authenticatedDebugAdapter.test.ts,test/noConfigDebugInit.test.ts, andtest/noConfigDebugStorage.test.ts)..vsixpaired with microsoft/java-debug#653 end-to-end in VS Code1.147.0withredhat.javaacrosslaunch,noDebug: true, andjdwp-wrapper.jsloopbackattach.